<?php
session_start();
?>

<head>
<script type="text/javascript" language="javascript" src="parts/usuarios/js/function_js.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery-1.3.2.min.js"></script>
</head>
<?php

include_once '../../lib/config_inc.php';
include_once '../../class/function.php';

		$variable = $_GET['v'];
		$id_usuario = $_GET['id'];
		$id_permisologia = $_SESSION["id_perfil"];
		$id_modulo=1;
		//$array_permisologia = consultar_permisologia($id_permisologia,$id_modulo);
				
?>

<form id="formulario" name="formulario" action="" onsubmit="return false">
<table  class="centrado borde" <?=$conf_tablas?> border="1">
    <tr>
        <td colspan="2" class="titulo">

            <div style="width:65%;padding:4px;float:left;">
                <span style="color:#ffffff">.::</span>
                Usuarios
            </div>

	   <div style="width:15%;padding:4px;float:left; font-size:12;">
	   	
		<a href="javascript:updateView('parts/usuarios/usuarios.php')">
		<img src="images/iconos/regresar.png" alt="Icono" title="Atrás"></a> Atrás
	
           </div>

            <div style="width:15%;padding:4px;float:left; font-size:12;">

		<a href="index.php">
		<img src="images/iconos/home-icon.png" alt="Icono" title="Inicio"></a> Inicio

            </div>
        </td>
    </tr>
  
    <?php /*Comienza Modificar Usuario */

	if($variable==2){ 
			$status=true;
			$array=consultar_usuario($id_usuario, $status); ?>

	<tr>
        	<td class="sombra1" style="width:25%">Nombres</td>
       		<td class="sombra2">

            	<input type="text" name="nombre" id="nombre" maxlength="50" size="20" value="<?php echo $array[0]['nb_usr'] ?>">

        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%">Apellidos</td>
       		<td class="sombra2">

            	<input type="text" name="apellido" id="apellido" maxlength="50" size="20" value="<?php echo $array[0]['ap_usr'] ?>">


        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Cedula</td>
       		<td class="sombra2">

            	<input type="text" name="cedula" id="cedula" maxlength="50" size="20" value="<?php echo $array[0]['cedula'] ?>">

        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Cargo</td>
       		<td class="sombra2">

            	<input type="text" name="cargo" id="cargo" maxlength="50" size="20" value="<?php echo $array[0]['tx_cargo'] ?>">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Teléfono</td>
       		<td class="sombra2">

            	<input type="text" name="tele" id="tele" maxlength="50" size="20" value="<?php echo $array[0]['telefono_usr']?>">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Correo</td>
       		<td class="sombra2">

            	<input type="text" name="correo" id="correo" maxlength="50" size="20" value="<?php echo $array[0]['correo_usr']?>">

        	</td>
	</tr>
				
	<tr>
		<td class="sombra1" style="width:25%">Perfil</td>
       		<td class="sombra2">

			<select name="Perfiles"  id="Perfiles" style="width:35%" onchange="refreshdiv_ente(this.value)">
			
			<option value="0">Seleccione</option>
			<?php 
			$sql2="SELECT * FROM t_cman_cargo WHERE id_cargo=".$array[0]["id_cargo"]."";
			$consul=ejecutar($sql2);
			$arreglo=pg_fetch_array($consul);
			echo "<option selected='selected' value=".$arreglo['id_cargo'].">".$arreglo["nb_cargo"]."</option>";

			$sql="SELECT * FROM t_cman_cargo WHERE id_cargo!=".$array[0]["id_cargo"]."";
			$consulta=ejecutar($sql);
			while($filas=pg_fetch_array($consulta)){
			echo "<option value=".$filas["id_cargo"].">".$filas["nb_cargo"]."</option>";
			}
			?>
			</select>
		
		</td>
	</tr>
		
	<tbody id="busca_ente">
	<?php if($array[0]["id_ente"]!=0) { ?>
		<tr>
			<td class="sombra1" style="width:25%">Ente</td>
			<td class="sombra2">
	
				<select name="ente"  id="ente" style="width:35%" onchange="refreshdiv_ente_adcrito(this.value)">
				
				<option value="0">Seleccione</option>
				<?php 
				$sql3="SELECT * FROM t_cman_entes_venezolanos WHERE id_ente_venezolano=".$array[0]["id_ente"]." AND in_status=1 AND id_ente_venezolano!=0";
				$consul=ejecutar($sql3);
				$arreglo=pg_fetch_array($consul);
				echo "<option selected='selected' value=".$arreglo['id_ente_venezolano'].">".$arreglo["nb_ente_venezolano"]."</option>";
	
				$sql4="SELECT * FROM t_cman_entes_venezolanos WHERE id_ente_venezolano!=".$array[0]["id_ente"]." AND id_ente_venezolano!=0";
				$consulta=ejecutar($sql4);
				while($filas=pg_fetch_array($consulta)){
				echo "<option value=".$filas["id_ente_venezolano"].">".$filas["nb_ente_venezolano"]."</option>";
				}
				?>
				</select>
			</td>
		</tr>
	<?php } ?>
	</tbody>
		
	<tbody id="busca_ente_adscrito">
	<?php if($array[0]["id_ente_adscrito"]!=0) { ?>
		<tr>
			<td class="sombra1" style="width:25%">Ente adscrito</td>
			<td class="sombra2">
	
				<select name="ente_ad"  id="ente_ad" style="width:35%">
				
				<option value="0">Seleccione</option>
				<?php 
				$sql3="SELECT * FROM t_cman_entes_venezolanos WHERE in_status=1 AND id_ente_venezolano!=0 and id_ente_padre=".$array[0]["id_ente"]." AND id_ente_venezolano=".$array[0]["id_ente_adscrito"];
				$consul=ejecutar($sql3);
				$arreglo=pg_fetch_array($consul);

				echo "<option selected='selected' value=".$arreglo['id_ente_venezolano'].">".$arreglo["nb_ente_venezolano"]."</option>";
	
				$sql4="SELECT * FROM t_cman_entes_venezolanos WHERE id_ente_venezolano!=".$array[0]["id_ente"]." AND id_ente_venezolano!=0";
				$consulta=ejecutar($sql4);
				while($filas=pg_fetch_array($consulta)){
				echo "<option value=".$filas["id_ente_venezolano"].">".$filas["nb_ente_venezolano"]."</option>";
				}
				?>
				</select>
			</td>
		</tr>
	<?php } ?>
	</tbody> 

	<tr>
		<td class="sombra1" style="width:25%">Subcomisión</td>
       		<td class="sombra2">

			<select name="subcomisiones"  id="subcomisiones" style="width:35%" onchange="refreshdiv_area(this.value)">	
			<option value="0">Seleccione</option>
			<?php 
			$sql2="SELECT * FROM t_cman_subcomisiones WHERE id_subcomision=".$array[0]["id_subcomision"]."";
			$consul=ejecutar($sql2);
			$arreglo=pg_fetch_array($consul);
			echo "<option selected='selected' value=".$arreglo['id_subcomision'].">".$arreglo["nb_subcomision"]."</option>";

			$sql="SELECT * FROM t_cman_subcomisiones WHERE id_subcomision!=".$array[0]["id_subcomision"]."";
			$consulta=ejecutar($sql);
			while($filas=pg_fetch_array($consulta)){
			echo "<option value=".$filas["id_subcomision"].">".$filas["nb_subcomision"]."</option>";
			}
			?>
			</select>
		
		</td>
	</tr>

	<tbody id="busca_area">
		<tr>
			<td class="sombra1" style="width:25%">Area</td>
			<td class="sombra2">
	
				<select name="areas"  id="areas" style="width:35%">
				
				<option value="0">Seleccione</option>
				<?php 
				$sql3="SELECT * FROM t_cman_areas_subcomisiones WHERE id_area=".$array[0]["id_area"]." AND id_area!=0 AND in_status=1";
				$consul=ejecutar($sql3);
				$arreglo=pg_fetch_array($consul);
				echo "<option selected='selected' value=".$arreglo['id_area'].">".$arreglo["nb_area"]."</option>";
	
				$sql4="SELECT * FROM t_cman_areas_subcomisiones WHERE id_area!=".$array[0]["id_area"]." AND in_status=1";
				$consulta=ejecutar($sql4);
				while($filas=pg_fetch_array($consulta)){
				echo "<option value=".$filas["id_area"].">".$filas["nb_area"]."</option>";
				}
				?>
				</select>
			</td>
		</tr>
	</tbody> 
		
	<tr>
        	<td class="sombra1" style="width:25%">Login usuario</td>
       		<td class="sombra2">

            	<input type="text" name="usuario" id="usuario" maxlength="50" size="20" value="<?php echo $array[0]['log_usr']?>"> 

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%">Status</td>
       		<td class="sombra2">

            		<input type="radio" name="stat" id="stat" value="1" checked="true"> Activada
			<input type="radio" name="stat" id="stat" value="2"> Desactivada

        	</td>
	
	</tr>

	<tr>
        	<td class="sombra3" colspan="2">
			<input type="hidden" name="accion"  id="accion"  value="<?php echo $variable?>">
			<input type="hidden" name="id"  id="id"  value="<?php echo $id_usuario?>">
			<a href="javascript:void(0)" onclick="valida_usuario()" class="nav">
			<img class="imagen-td" src=images/boton_actualizar.jpg  title="Modificar"></a>
		</td>
	</tr>

	<?php } /* Finaliza Modificar Usuario */ 
		
		/* Comienza Eliminar Usuario */
	else {if($variable==0){
			$status=true;
			$array=consultar_usuario($id_usuario, $status); ?>
	

	<tr>
        	<td class="sombra1" style="width:25%">Nombres</td>
       		<td class="sombra2">

            	<input type="text" name="nombre" id="nombre" maxlength="50" size="20" value="<?php echo $array[0]['nb_usr'] ?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%">Apellidos</td>
       		<td class="sombra2">

            	<input type="text" name="apellido" id="apellido" maxlength="50" size="20" value="<?php echo $array[0]['ap_usr'] ?>" readonly="true" style ="background-color:#E7E7E7">


        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Cedula</td>
       		<td class="sombra2">

            	<input type="text" name="cedula" id="cedula" maxlength="50" size="20" value="<?php echo $array[0]['cedula'] ?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Cargo</td>
       		<td class="sombra2">

            	<input type="text" name="cargo" id="cargo" maxlength="50" size="20" value="<?php echo $array[0]['tx_cargo'] ?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Teléfono</td>
       		<td class="sombra2">

            	<input type="text" name="tele" id="tele" maxlength="50" size="20" value="<?php echo $array[0]['telefono_usr']?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Correo</td>
       		<td class="sombra2">

            	<input type="text" name="correo" id="correo" maxlength="50" size="20" value="<?php echo $array[0]['correo_usr']?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Fecha registro</td>
       		<td class="sombra2">

            	<input type="text" name="fecha_reg" id="fecha_reg" maxlength="50" size="20" value="<?php echo $array[0]['fe_rgto_usr']?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>

	<tr>
		<td colspan="2" class="titulo">
			<div style="width:65%;padding:4px;float:left;">
				<span style="color:#FFFFFF">.::</span>Cuenta del Usuario
			</div>  
		</td>
			
	</tr>
		
		
	<tr>
		<td class="sombra1" style="width:25%"><?=$obliga?>Perfil</td>
       		<td class="sombra2">

		<input type="text" name="Perfiles" id="Perfiles" maxlength="50" size="20" value="<?php echo $array[0]['nb_cargo'] ?>" readonly="true" style ="background-color:#E7E7E7">
		
		</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%">Login  Usuario</td>
       		<td class="sombra2">

            	<input type="text" name="usuario" id="usuario" maxlength="50" size="20" value="<?php echo $array[0]['log_usr']?>" readonly="true" style ="background-color:#E7E7E7"> 

        	</td>
	</tr>


	<tr>

        	<td class="sombra3" colspan="2">
			<input type="hidden" name="accion"  id="accion"  value="<?php echo $variable?>">
			<input type="hidden" name="id"  id="id"  value="<?php echo $id_usuario?>">
			<a href="javascript:void(0)" onclick="elimina_usuario()" class="nav">
			<img class="imagen-td" src=images/boton_eliminar.jpg title="Eliminar"></a>
		</td>
	</tr>

<?php }} /* Finaliza Eliminar Usuario Usuario */  

	/* Comienza insertar usuario */
	if($variable==1){ ?>
 	
	<tr>
        	<td class="sombra1" style="width:25%">Nombre</td>
       		<td class="sombra2">
			<input type="text" name="nombre" id="nombre" maxlength="50" size="20">
        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%">Apellido</td>
       		<td class="sombra2">
            		<input type="text" name="apellido" id="apellido" maxlength="50" size="20"> 
	
        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%">Cedula</td>
       		<td class="sombra2">

            		<input type="text" name="cedula" id="cedula" maxlength="50" size="20">

        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%">Cargo</td>
       		<td class="sombra2">
            		<input type="text" name="cargo" id="cargo" maxlength="50" size="20">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%">Telefono</td>
       		<td class="sombra2">

            		<input type="text" name="tele" id="tele" maxlength="50" size="20">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%">Correo</td>
       		<td class="sombra2">

            		<input type="text" name="correo" id="correo" maxlength="50" size="20">

        	</td>
	</tr>

	<tr>
		<td colspan="2" class="titulo">
			<div style="width:65%;padding:4px;float:left;">
				<span style="color:white">.::</span>Cuenta del Usuario
			</div>  
		</td>
			
	</tr>
		
		
	<tr>
		<td class="sombra1" style="width:25%">Perfil</td>
       		<td class="sombra2">

			<select name="Perfiles"  id="Perfiles" style="width:35%" onchange="refreshdiv_ente(this.value)">
			
			<option value="0">Seleccione</option>
			<?php 
			$sql="SELECT * FROM t_cman_cargo WHERE in_status=1";
			$consulta=ejecutar($sql);
					
			while($filas=pg_fetch_array($consulta)){
				echo "<option value=".$filas["id_cargo"].">".$filas["nb_cargo"]."</option>";
			}
		?>
			</select>
		
		</td>
	</tr>
		

	<tbody id="busca_ente">

	</tbody>

	<tbody id="busca_ente_adscrito">

	</tbody>
	<tr>
		<td class="sombra1" style="width:25%">Subcomisión</td>
       		<td class="sombra2">

			<select name="subcomisiones"  id="subcomisiones" style="width:35%" onchange="refreshdiv_area(this.value)">
			
			<option value="0">Seleccione</option>
			<?php 
			$sql="SELECT * FROM t_cman_subcomisiones WHERE in_status=1";
			$consulta=ejecutar($sql);
					
			while($filas=pg_fetch_array($consulta)){
				echo "<option value=".$filas["id_subcomision"].">".$filas["nb_subcomision"]."</option>";
			}
		?>
			</select>
		
		</td>
	</tr>

	<tbody id="busca_area">

	</tbody>
		
	<tr>
        	<td class="sombra1" style="width:25%">Login Usuario</td>
       		<td class="sombra2">

            		<input type="text" name="usuario" id="usuario" maxlength="50" size="20">

        	</td>
	</tr>
		

	<tr>
        	<td colspan="2" class="sombra3">

            		<input type="reset" value="Limpiar">
            			
		</td>
    	</tr>
	
	<tr>
        	<td class="sombra3" colspan="2">
			<input type="hidden" name="accion"  id="accion"  value="<?php echo $variable?>">
			<a href="javascript:void(0)" onclick="valida_usuario()" class="nav">
			<img class="imagen-td" src=images/boton_insertar.jpg title="Insertar"></a>
		</td>
	</tr>

	
		
		
	<?php  }  /* Finaliza insertar usuario */ 
			
  	

	/* Comienza Consultar Usuarios */
	else{ 
		if($variable==3 || $variable==4)
		{
			if($variable==4)
			{
				$array=consultar_usuario($id_usuario, $status);
			}
			else
			{
				$status=true;
				$array=consultar_usuario($id_usuario, $status);

			} 
			?>  
	
	<tr>
        	<td class="sombra1" style="width:25%">Nombres</td>
       		<td class="sombra2">

            	<input type="text" name="nombre" id="nombre" maxlength="50" size="20" value="<?php echo $array[0]['nb_usr'] ?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%">Apellidos</td>
       		<td class="sombra2">

            	<input type="text" name="apellido" id="apellido" maxlength="50" size="20" value="<?php echo $array[0]['ap_usr'] ?>" readonly="true" style ="background-color:#E7E7E7">


        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Cedula</td>
       		<td class="sombra2">

            	<input type="text" name="cedula" id="cedula" maxlength="50" size="20" value="<?php echo $array[0]['cedula'] ?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Cargo</td>
       		<td class="sombra2">

            	<input type="text" name="cargo" id="cargo" maxlength="50" size="20" value="<?php echo $array[0]['tx_cargo'] ?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Teléfono</td>
       		<td class="sombra2">

            	<input type="text" name="tele" id="tele" maxlength="50" size="20" value="<?php echo $array[0]['telefono_usr']?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Correo</td>
       		<td class="sombra2">

            	<input type="text" name="correo" id="correo" maxlength="50" size="20" value="<?php echo $array[0]['correo_usr']?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>

	<tr>
        	<td class="sombra1" style="width:25%"><?=$obliga?>Fecha registro</td>
       		<td class="sombra2">

            	<input type="text" name="fecha_reg" id="fecha_reg" maxlength="50" size="20" value="<?php echo $array[0]['fe_rgto_usr']?>" readonly="true" style ="background-color:#E7E7E7">

        	</td>
	</tr>

	<tr>
		<td colspan="2" class="titulo">
			<div style="width:65%;padding:4px;float:left;">
				<span style="color:#FFFFFF">.::</span>Cuenta del Usuario
			</div>  
		</td>
			
	</tr>
		
		
	<tr>
		<td class="sombra1" style="width:25%"><?=$obliga?>Perfil</td>
       		<td class="sombra2">

		<input type="text" name="Perfiles" id="Perfiles" maxlength="50" size="20" value="<?php echo $array[0]['nb_cargo'] ?>" readonly="true" style ="background-color:#E7E7E7">
		
		</td>
	</tr>

	<?php if($array[0]["id_ente"]!=0) { ?>
	<tr>
		<td class="sombra1" style="width:25%"><?=$obliga?>Ente</td>
       		<td class="sombra2">

		<input type="text" name="Perfiles" id="Perfiles" maxlength="50" size="20" value="<?php echo $array[0]['nb_ente_venezolano'] ?>" readonly="true" style ="background-color:#E7E7E7">
		
		</td>
	</tr>
	<? } ?>
	<tr>
		<td class="sombra1" style="width:25%"><?=$obliga?>Subcomision</td>
       		<td class="sombra2">

		<input type="text" name="Perfiles" id="Perfiles" maxlength="50" size="20" value="<?php echo $array[0]['nb_subcomision'] ?>" readonly="true" style ="background-color:#E7E7E7">
		
		</td>
	</tr>

	<tr>
		<td class="sombra1" style="width:25%"><?=$obliga?>Area</td>
       		<td class="sombra2">

		<input type="text" name="Perfiles" id="Perfiles" maxlength="50" size="20" value="<?php echo $array[0]['nb_area'] ?>" readonly="true" style ="background-color:#E7E7E7">
		
		</td>
	</tr>
		
	<tr>
        	<td class="sombra1" style="width:25%">Login usuario</td>
       		<td class="sombra2">

            	<input type="text" name="usuario" id="usuario" maxlength="50" size="20" value="<?php echo $array[0]['log_usr']?>" readonly="true" style ="background-color:#E7E7E7"> 

        	</td>
	</tr>

	<?php if($variable==3){ ?>
	<?php //if($array_permisologia[0]["modificar"]==t){ ?>
	<tr>
        	<td class="sombra3" colspan="2" style="font-size:12; font-color:black;">
		<a href="javascript:updateView('parts/usuarios/index_usuarios?v=2&id=<?php echo $array[0]["id_usr"];?>')" onmouseover="window.status=''; return true">
		<img class="imagen-td" src=images/iconos/edit-page.png alt=Icono title=Modificar align="center"></a> Modificar
		</td>
	</tr>
	<?php  // } ?>
	<?php }else if($variable==4){ ?>

	<tr>
        	<td class="sombra3" colspan="2" style="font-size:12; font-color:black;">
		<input type="hidden" name="accion"  id="accion"  value="<?php echo $variable?>">
		<input type="hidden" name="id"  id="id"  value="<?php echo $array[0]["id_usr"]?>">
		<a href="javascript:void(0)" onclick="cambiar_estatus()" class="nav">
		<img class="imagen-td" src=images/activar.jpg alt=Icono title=Activar align="center"></a>
		</td>
	</tr>

	<?php } ?>


	<?php }} /* Finaliza Consultar Usuario */  ?>	
	
</table>
</form>